package com.cskaoyan.service.admin;

import com.cskaoyan.bean.MarketLog;
import com.cskaoyan.bean.MarketLogExample;
import com.cskaoyan.mapper.MarketLogMapper;
import com.cskaoyan.model.admin.bo.BaseParam;
import com.cskaoyan.model.admin.vo.BaseDataListVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author hanshuai
 * @version 1.0
 * @description @TODO
 * @date 2021/11/30 13:59
 */
@Service
public class AdminLogServiceImpl implements AdminLogService {
    @Autowired
    MarketLogMapper marketLogMapper;

    @Override
    public BaseDataListVo logList(BaseParam baseParam, String name) {
        PageHelper.startPage(baseParam.getPage(), baseParam.getLimit());
        MarketLogExample marketLogExample = new MarketLogExample();
        if (name != null) {
            marketLogExample.createCriteria().andAdminLike("%" + name + "%");
        }
        marketLogExample.setOrderByClause(baseParam.getSort() + " " + baseParam.getOrder());
        List<MarketLog> marketLogs = marketLogMapper.selectByExample(marketLogExample);
        PageInfo pageInfo = new PageInfo(marketLogs);
        BaseDataListVo baseDataListVo = new BaseDataListVo();
        baseDataListVo.setList(marketLogs);
        baseDataListVo.setLimit(baseParam.getLimit());
        baseDataListVo.setPage(baseParam.getPage());
        baseDataListVo.setPages(pageInfo.getPages());
        baseDataListVo.setTotal((int) pageInfo.getTotal());
        return baseDataListVo;
    }
}
